
class Domain:
	def __init__(self,iterator):
		self.name = iterator.next()
		self.types = iterator.next()
		self.constants =  iterator.next()
		self.predicates = [Predicate(x,self.types) for x in iterator.next()]
		self.actions = [Action(x,self.types) for x in iterator.next() ]

class Action:
	
	# used to by PlanningProblem to store a working substitution to be used for
	# effect
	substitution = []
	def __init__(self,l,types):
		self.name = l[0]
		self.parameters = l[1] # list of typed x tuples (x,type_of_x)
		# check if the parameters type is valid or not
		self.variables = []
		for i in  self.parameters:
			if i[1] not in types: raise Exception("Action %s Parameter type mismatch"%self.name)
		for var in [i[0] for i in self.parameters]:
			self.variables.append(var)
		# make it unique
		self.variables = list(set(self.variables))

		self.preconditions = l[2]
		# Effect:
		self.ADD = l[3][0]
		self.DEL = l[3][1]
		
		#TODO
		# check the atoms of syntax and types for precondition, Effect
	def __repr__(self):
		return self.name
class Predicate:
	def __init__(self,l,types):
		self.name = l[0]
		self.varList = l[1] # varlist is a list of tuples (x,type_of_x)
		for i in  self.varList:
			if i[1] not  in types: raise Exception("Predicate %s: Parameter type mismatch"%self.name)
	def __repr__(self):
		return self.name + self.varList.__repr__()
